package com.authen.utils;

import android.graphics.Bitmap;

public class ImageUtil {
	public static Bitmap bitmapCrop(Bitmap src, int left, int top, int right, int bottom) {
		int width = src.getWidth();
		int height = src.getHeight();
	    left   = Math.min(Math.max(left, 0), width-1);
	    top    = Math.min(Math.max(top, 0), height-1);
	    right  = Math.min(Math.max(right, 0), width-1);
	    bottom = Math.min(Math.max(bottom, 0), height-1);
	    
		int rectWidth = right - left;
		int rectHieght = bottom - top;
		if (rectWidth <= 0 || rectHieght <= 0) {
			return null;
		}
		return Bitmap.createBitmap(src, left, top, rectWidth, rectHieght, null, false);
	}
}
